package com.rtx.edi.gatway.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rtx.api.annotation.DataSourceAnnotation;
import com.rtx.edi.gatway.dao.GatWayHandleDAO;
import com.rtx.edi.gatway.mapper.GatWayHandleMapper;

@Service
public class GatWayHandleDAOMysqlImpl implements GatWayHandleDAO{

	
	@Autowired
	GatWayHandleMapper gatWayHandleMapper;

	@Transactional
	public void saveDynamicCreateSql(List<String> sqlList) {
		for(String sql:sqlList) {
			gatWayHandleMapper.insertSql(sql);
		}
	}
	
	public void saveDynamicCreateSql(String sql) {
		gatWayHandleMapper.insertSql(sql);
	}

	@Transactional
	@Override
	public void updDynamicCreateSql(List<String> sqlList) {
		for(String sql:sqlList) {
			gatWayHandleMapper.updSql(sql);
		}
	}
	
	@Override
	public void updDynamicCreateSql(String sql) {
		gatWayHandleMapper.updSql(sql);
	}

	@DataSourceAnnotation
	@Override
	public String selectActiveWhseidNotEnterprise(String datasourcekey) {
		List<String> activeWhseidList = Optional.ofNullable(gatWayHandleMapper.selectActiveWhseidNotEnterprise()).orElse(new ArrayList<>());
		return activeWhseidList.stream().collect(Collectors.joining(","));
	}
	
	@DataSourceAnnotation
	@Override
	public String selectWmseid(String datasourcekey,String sql) {
		return gatWayHandleMapper.selectwhseid(sql);
	}
	
	
}
